home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / bc_ti.zip / TI649.ASC < prev    next >
Text File  |  1992-02-25  |  14KB  |  463 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                            NUMBER  :  649
  9.   VERSION  :  2.0
  10.        OS  :  PC DOS
  11.      DATE  :  February 25, 1992                        PAGE  :  1/7
  12.  
  13.     TITLE  :  Common Causes of General Protection Faults
  14.  
  15.  
  16.  
  17.  
  18.   WHAT? GENERAL PROTECTION ERROR!
  19.  
  20.   Protected mode development tools permit much  larger  programs to
  21.   be  compiled  faster  than their real mode  counterparts.    They
  22.   accomplish this by allowing  the  use  of  a vastly larger memory
  23.   area  than  is  available to real mode tools. There is a cost for
  24.   this  increased  capability,  however; many of us  will  have  to
  25.   change the coding practices and strategies we grew  to  depend on
  26.   with the relatively tolerant real mode development tools.
  27.  
  28.   Central to this change  is  the  increasingly  notorious "General
  29.   Protection Fault."   A  GP  Fault  is generated by what one might
  30.   think of as a debugger built into the CPU and is enabled any time
  31.   a program is operating in protected mode.  This debugger-in-a-CPU
  32.   is very, very uncompromising  with  regard  to  the rules which a
  33.   program  must  obey  while  availing  itself  of  protected  mode
  34.   capabilities.
  35.  
  36.   For  example, suppose a block of memory  is  allocated  for  use.
  37.   Further suppose that we code an errant read or write outside this
  38.   block.  In real mode this  may  show  up in a variety of more-or-
  39.   less unacceptable ways; many of these we can choose to ignore.
  40.  
  41.   The  same  program  executed  in  protected  mode  will,  in  all
  42.   probably, display a General Protection  Fault  error  message and
  43.   immediately exit to DOS.   This illustrates the cost of operating
  44.   in  protected  mode;  our  right  to  ignore  coding problems  is
  45.   seriously limited.
  46.  
  47.   There is an upside to this, however: any program  that  runs  for
  48.   any length of time in protected mode is likely to be far more bug
  49.   free than an equivalent program executed only in real mode.
  50.  
  51.   General Protection Faults are generated,  however,  by  more than
  52.   just reads or writes outside proper memory areas.
  53.  
  54.   The following list, extracted  from  the  Intel  386 Programmer's
  55.   Reference Manual, serves to  suggest  the  level  of "protection"
  56.   which we may expect while operating in protected mode:
  57.  
  58.   -----------------------------------------------------------------------
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland C++                            NUMBER  :  649
  75.   VERSION  :  2.0
  76.        OS  :  PC DOS
  77.      DATE  :  February 25, 1992                        PAGE  :  2/7
  78.  
  79.     TITLE  :  Common Causes of General Protection Faults
  80.  
  81.  
  82.  
  83.  
  84.   All protection violations which do  not  cause  another exception
  85.   cause  a General-Protection Fault.  This  includes  (but  is  not
  86.   limited to):
  87.  
  88.   a.  Exceeding the segment limit when using CS, DS, ES, FS, or GS
  89.       segments
  90.  
  91.   b.  Exceeding the segment limit when referencing a descriptor
  92.       table
  93.  
  94.   c.  Transferring execution to a segment which is not executable
  95.  
  96.   d.  Writing to a read-only data segment or a code segment
  97.  
  98.   e.  Reading from an execute-only code segment
  99.  
  100.   f.  Loading the SS register with a selector for a read-only
  101.       segment (unless the  selector comes from a TSS during a  task
  102.       switch, in which case an invalid-TSS exception occurs)
  103.  
  104.   g.  Loading the SS, DS, ES, FS, or GS register with a selector
  105.       for a system segment
  106.  
  107.   h.  Loading the DS, ES, FS, or GS register with a selector for an
  108.       execute-only code segment
  109.  
  110.   i.  Loading the SS register with the selector of an executable
  111.       segment
  112.  
  113.   j.  Accessing memory using the DS, ES, FS, or GS register when it
  114.       contains a null selector
  115.  
  116.   k.  Switching to a busy task
  117.  
  118.   l.  Violating privilege rules
  119.  
  120.   m.  Exceeding the instruction length limit of 15 bytes (this only
  121.       can occur when redundant prefixes are placed before an
  122.       instruction)
  123.  
  124.   n.  Loading the CRO register with a set PG bit (paging enabled)
  125.       and a clear PE bit (protection disabled)
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Borland C++                            NUMBER  :  649
  141.   VERSION  :  2.0
  142.        OS  :  PC DOS
  143.      DATE  :  February 25, 1992                        PAGE  :  3/7
  144.  
  145.     TITLE  :  Common Causes of General Protection Faults
  146.  
  147.  
  148.  
  149.  
  150.   o.  Interrupt or exception through an interrupt or trap gate from
  151.       virtual-8086 mode to a handler at a privilege level other
  152.       than 0
  153.  
  154.   p.  The general-protection exception is a fault. In response to a
  155.       general-protection exception, the processor pushes an error
  156.       code onto the exception handler's stack.  If loading a
  157.       descriptor causes the exception, the error code contains a
  158.       selector to the descriptor; otherwise, the error code is
  159.       null.  The source of the selector in an error code may be any
  160.       of the following:
  161.  
  162.      1.  An operand of the instruction
  163.  
  164.      2.  A  selector  from  a gate which  is  the  operand  of  the
  165.          instruction
  166.  
  167.      3.  A selector from a TSS involved in a task switch
  168.  
  169.    -----------------------------------------------------------------------
  170.  
  171.   PROGRAM OR DEVELOPMENT TOOL?
  172.  
  173.   Obviously  if your applications are going to  be  subject  to  GP
  174.   Fault  errors  it  stands to reason that  the  development  tools
  175.   themselves must abide by  the  same rules and are subject to this
  176.   demanding debugger-in-a-CPU.
  177.  
  178.   It  is  unlikely  that any significant program has ever been bug-
  179.   free  and  Borland's  development tools are no different.  As you
  180.   might expect, we are dedicated to eliminating any  bugs  that can
  181.   be identified. One might guess that this would be an easy task.
  182.  
  183.   Unfortunately  the protected mode mechanism does not  distinguish
  184.   between problems in the code  being developed under the tools and
  185.   problems with the tools  themselves.    Consequently,  it becomes
  186.   necessary for the developer  to  take  additional steps to assure
  187.   that their code is not the cause.  Although there is  little that
  188.   Borland can do  to  make  this  process easier, we can supply you
  189.   with a list  of  known  problems  in the BC++ tools that generate
  190.   reproducible  GP Fault errors.  If you find  a  problem  you  are
  191.   encountering on this list you can eliminate your  program  as the
  192.   culprit.
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  Borland C++                            NUMBER  :  649
  207.   VERSION  :  2.0
  208.        OS  :  PC DOS
  209.      DATE  :  February 25, 1992                        PAGE  :  4/7
  210.  
  211.     TITLE  :  Common Causes of General Protection Faults
  212.  
  213.  
  214.  
  215.  
  216.       -  Moving  the  mouse  while  BCX  is setting up to run  your
  217.          program  can cause a GP Fault.  This  can  happen  if  the
  218.          mouse  is  moving  when  BCX  switches  from  compiling to
  219.          linking also but  not  nearly as often as choosing RUN|RUN
  220.          and moving the mouse after the link or dependency check.
  221.  
  222.       -  Window Resize/Move-  Clicking  the  mouse  almost anywhere
  223.          outside  of a BCX window set up  for  resizing  or  moving
  224.          (green bordered)
  225.  
  226.       -  Using the ,m (memory dump) option in a BCX watch window
  227.  
  228.       -  Doing  a  Repaint  Desktop  in  BCX with a  HERCULES  card
  229.          attached (and any video cards doing Hercules simulation)
  230.  
  231.       -  Compiling a program under BCX using  the  ternary operator
  232.          with the second or third variables undefined
  233.  
  234.       -  Compiling a program with the OPTIONS|DIRECTORY|INCLUDE box
  235.          filled to its maximum
  236.  
  237.       -  Inspecting  on a static member of a  class  with  the  BCX
  238.          debugger
  239.  
  240.       -  Compiling  the  DLLDEMO  examples  program under BCX using
  241.          different segment names for BSS or DATA
  242.  
  243.   Ok, so the problem can't be in your application because  you have
  244.   reduced it to the point where all it does is print "Hello, world"
  245.   and it's still giving you a GP Fault; and it's not on the list of
  246.   known problems.
  247.  
  248.   There are two final sources  of  General  Protection  Faults that
  249.   have little to do with either the tools or the  application under
  250.   dev